package org.niux.aims.common.tag;

import java.io.Writer;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.components.Component;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * 
 * Copyright (c) 2009,niux<br>
 * All rights reserved.<br>
 * 
 * 文件名称：AuthTagComponent.java<br>
 * 摘    要：权限组件标签实现类<br>
 * <br>
 * 当前版本：<br>
 * 作    者：铭显 Email: <a href="mailto:liangmingxian@gmail.com">liangmingxian@gmail.com</a><br>
 * 完成日期：@since 2013-10-26<br>
 * <br>
 * 取代版本：<br>
 * 原作者  ：<br>
 * 完成日期：@since Oct 22, 2009<br>
 */
public class AuthTagComponent extends Component {

	private String entityCode;
	private HttpServletRequest session;
	
	public AuthTagComponent(ValueStack stack,HttpServletRequest session) {
		super(stack);
		this.session = session;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean start(Writer writer) {
		List<String> auths = (List<String>)session.getSession().getAttribute("auths");
		if(auths.contains(entityCode) || auths.isEmpty()){
			return true;
		} else {
			return false;
		}
	}
	
	@Override
	public boolean end(Writer writer, String body) {
		return super.end(writer, body);
	}

	public String getEntityCode() {
		return entityCode;
	}

	public void setEntityCode(String entityCode) {
		this.entityCode = entityCode;
	}

}
